"""
使用Python3.5+的新语法async和await让coroutine的代码更简洁易读。

async和await是针对coroutine的新语法，要使用新的语法，只需要做两步简单的替换：
    1.把@asyncio.coroutine替换为async；
    2.把yield from替换为await。
"""

import asyncio
import threading


async def say_hello():
    print("hello python! {name}".format(name=threading.current_thread().name))
    await asyncio.sleep(3)
    print("hello again! {name}".format(name=threading.current_thread().name))


def run():
    # 获取消息循环
    loop = asyncio.get_event_loop()
    tasks = [say_hello(), say_hello()]
    loop.run_until_complete(asyncio.wait(tasks))
    loop.close()


if __name__ == "__main__":
    run()
